package com.business.systemmanage.controller;


import com.business.systemmanage.common.entity.ResponseInfo;
import com.business.systemmanage.entity.UserInfo;
import com.business.systemmanage.service.IUserInfoService;
import com.business.systemmanage.vo.UserInfoVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author sixDog
 * @since 2019-04-12
 */
@RestController
@RequestMapping("/systemmanage/userInfo")
public class UserInfoController {
    @Autowired
    private IUserInfoService iUserInfoService;

    @ApiOperation(
            value = "根据用户id获取用户信息",
            notes = "用户id要填写整数哦",
            tags = {"用户"})
    @ApiImplicitParam(paramType = "query", name = "id", value = "id", required = true, dataType = "Long")
    @RequestMapping("/find")
    public ResponseInfo find(@RequestParam Long id) {
        try {
            UserInfo userInfo = iUserInfoService.getById(id);
            return ResponseInfo.generateObjectRes(userInfo);
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }

    @ApiOperation(
            value = "注册用户信息",
            notes = "注册用户信息",
            tags = {"用户"})
    @RequestMapping("/register")
    public ResponseInfo register(@RequestBody UserInfoVO userInfoVO) {
        try {
            iUserInfoService.register(userInfoVO);
            return ResponseInfo.generateSuccessRes();
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }

}
